
package com.ys.chatserver;

import com.eva.epc.common.util.CommonUtils;
import com.eva.epc.common.util.Platform;
import com.eva.epc.common.util.PropertyMan;
import com.eva.framework.utils.LoggerFactory;

import java.nio.charset.StandardCharsets;

public class BaseConf {
    private PropertyMan pm = null;

    private final static String TAG = BaseConf.class.getSimpleName();
    private static BaseConf instance = null;


    public static BaseConf getInstance() {
        if (instance == null)
            instance = new BaseConf();
        return instance;
    }

    public BaseConf() {
//		String path = "/E:/Program Files/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/RobotimeMissU_s_new/WEB-INF/classes/com/robotime/missu_s/ends/base_conf.properties";
        String pathOriginal = BaseConf.class.getResource("base_conf.properties").getPath();
        String path = Platform.isWindows() ? pathOriginal.substring(1) : pathOriginal;
        LoggerFactory.getLog().debug("[" + TAG + "] RainbowChat服务端的核心配置文件路径：" + path);
        pm = new PropertyMan(path);
    }

    /**
     * TODO 本方法以后可考虑收纳到父类中！
     * 因Properties文件默认机制是采用ISO8859-1处理的，所以中文字符读取会存在乱码现象。
     * 本方法是在父类方法的基础上解决乱码问题。
     */
    public String getPropertyUTF(String key) {
        try {
            String s = pm.getProperty(key);
            return new String(s.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        } catch (Exception e) {
            LoggerFactory.getLog().error("[" + TAG + "] RainbowChat的配置项：" + key
                    + " 读取失败，请检查您的配置文件路径是否放置正确！", e);
            return null;
        }
    }

    public String getDIR_USER_AVATAR_UPLOAD() {
        return getPropertyUTF("DIR_USER_AVATAR_UPLOAD");
    }

    public String getDIR_USER_AVATARGROUP_DIR() {
        return getPropertyUTF("DIR_USER_AVATARGROUP_DIR");
    }

    public String getDIR_USER_IMAGE_UPLOAD_UNREAD() {
        return getPropertyUTF("DIR_USER_IMAGE_UPLOAD_UNREAD");
    }

    public String getDIR_USER_IMAGE_UPLOAD_READ() {
        return getPropertyUTF("DIR_USER_IMAGE_UPLOAD_READ");
    }

    public String getDIR_USER_IMAGE_UPLOAD_TIMEOUT() {
        return getPropertyUTF("DIR_USER_IMAGE_UPLOAD_TIMEOUT");
    }

    public String getDIR_USER_VOICE_UPLOAD_UNREAD() {
        return getPropertyUTF("DIR_USER_VOICE_UPLOAD_UNREAD");
    }

    public String getDIR_USER_VOICE_UPLOAD_READ() {
        return getPropertyUTF("DIR_USER_VOICE_UPLOAD_READ");
    }

    public String getDIR_USER_VOICE_UPLOAD_TIMEOUT() {
        return getPropertyUTF("DIR_USER_VOICE_UPLOAD_TIMEOUT");
    }


    public String getDIR_USER_BIGFILE_UPLOAD() {
        return getPropertyUTF("DIR_USER_BIGFILE_UPLOAD");
    }

    public String getDIR_USER_SHORTVIDEO_UPLOAD() {
        return getPropertyUTF("DIR_USER_SHORTVIDEO_UPLOAD");
    }

    public String getDIR_USER_SHORTVIDEO_UPLOAD_TIMEOUT() {
        return getPropertyUTF("DIR_USER_SHORTVIDEO_UPLOAD_TIMEOUT");
    }

    public String getAUTO_TIMING_RESTORE_IMG_AND_VOICE_INTERVAL() {
        return getPropertyUTF("AUTO_TIMING_RESTORE_IMG_AND_VOICE_INTERVAL");
    }

    public String getAUTO_TIMING_RESTORE_IMG_AND_VOICE_TIMEOUT() {
        return getPropertyUTF("AUTO_TIMING_RESTORE_IMG_AND_VOICE_TIMEOUT");
    }

    public String getDIR_USER_PHOTO_UPLOAD() {
        return getPropertyUTF("DIR_USER_PHOTO_UPLOAD");
    }

    public String getDIR_USER_PVOICE_UPLOAD() {
        return getPropertyUTF("DIR_USER_PVOICE_UPLOAD");
    }

    public String getDIR_USER_LOCATION_UPLOAD_UNREAD() {
        return getPropertyUTF("DIR_USER_LOCATION_UPLOAD_UNREAD");
    }

    public String getDIR_USER_LOCATION_UPLOAD_READ() {
        return getPropertyUTF("DIR_USER_LOCATION_UPLOAD_READ");
    }

    public String getDIR_USER_LOCATION_UPLOAD_TIMEOUT() {
        return getPropertyUTF("DIR_USER_LOCATION_UPLOAD_TIMEOUT");
    }

    public String getDIR_USER_REMARK_PHOTO_UPLOAD() {
        return getPropertyUTF("DIR_USER_REMARK_PHOTO_UPLOAD");
    }

    public boolean getIM_BRIDGE_ENABLED() {
        return Boolean.parseBoolean(getPropertyUTF("IM_BRIDGE_ENABLED"));
    }

    public String getIM_BRIDGE_MQ_URI() {
        return getPropertyUTF("IM_BRIDGE_MQ_URI");
    }


    /**
     * 获取云盘图片存储路径
     */
    public String getDIR_CLOUD_IMAGE_UPLOAD() {
        return getPropertyUTF("DIR_CLOUD_IMAGE_UPLOAD");
    }

    /**
     * 获取云盘视频存储路径
     */
    public String getDIR_CLOUD_VIDEO_UPLOAD() {
        return getPropertyUTF("DIR_CLOUD_VIDEO_UPLOAD");
    }

    public String getDIR_NETTY_TLS_ROOT() {
        return getPropertyUTF("DIR_NETTY_TLS_ROOT");
    }

    public int getIM_SERVER_UDP_LISTENNING_PORT() {
        return CommonUtils.getIntValue(getPropertyUTF("IM_SERVER_UDP_LISTENNING_PORT")
                , 9903);
    }

    public int getIM_SERVER_TCP_LISTENNING_PORT() {
        return CommonUtils.getIntValue(getPropertyUTF("IM_SERVER_TCP_LISTENNING_PORT")
                , 9903);
    }

    public int getIM_SERVER_WEBSOCKET_LISTENNING_PORT() {
        return CommonUtils.getIntValue(getPropertyUTF("IM_SERVER_WEBSOCKET_LISTENNING_PORT")
                , 9903);
    }

    public int getNGINX_IM_SERVER_WEBSOCKET_LISTENNING_PORT() {
        return CommonUtils.getIntValue(getPropertyUTF("NGINX_IM_SERVER_TCP_LISTENNING_PORT")
                , 20001);
    }


    public int getIM_SERVER_SOCKETIO_LISTENNING_PORT() {
        return CommonUtils.getIntValue(getPropertyUTF("IM_SERVER_SOCKETIO_LISTENNING_PORT")
                , 5000);
    }

    public boolean getIM_SERVER_UDP_SUPPORT() {
        return Boolean.parseBoolean(getPropertyUTF("IM_SERVER_UDP_SUPPORT"));
    }

    public boolean getIM_SERVER_TCP_SUPPORT() {
        return Boolean.parseBoolean(getPropertyUTF("IM_SERVER_TCP_SUPPORT"));
    }

    public boolean getIM_SERVER_WEBSOCKET_SUPPORT() {
        return Boolean.parseBoolean(getPropertyUTF("IM_SERVER_WEBSOCKET_SUPPORT"));
    }

    public boolean getIM_SERVER_SOCKETIO_SUPPORT() {
        return Boolean.parseBoolean(getPropertyUTF("IM_SERVER_SOCKETIO_SUPPORT"));
    }

    public String getAUTO_TIMING_RESTORE_MESSAGES_INTERVAL() {
        return getPropertyUTF("AUTO_TIMING_RESTORE_MESSAGES_INTERVAL");
    }

    public String getAUTO_TIMING_RESTORE_MESSAGES_TIMEOUT() {
        return getPropertyUTF("AUTO_TIMING_RESTORE_MESSAGES_TIMEOUT");
    }

    public boolean getAUTO_PREPARED_DEMO_DATAS() {
        return Boolean.parseBoolean(getPropertyUTF("AUTO_PREPARED_DEMO_DATAS"));
    }

    public String getNETTY_SSL_KEY_PASSWORD() {
        return getPropertyUTF("NETTY_SSL_KEY_PASSWORD");
    }

    public String getFTP_BAK_DIR() {
        return getPropertyUTF("FTP_BAK_DIR");
    }

    public String getFTP_BAK_GROUP_EXPIRE_TTL() {
        return getPropertyUTF("FTP_BAK_GROUP_EXPIRE_TTL");
    }

    public String getIS_BAK_SERVER() {
        return getPropertyUTF("IS_BAK_SERVER");
    }

    /**
     * 获取云盘视频存储路径
     */
    public String getDIR_CLOUD_LIVE_VIDEO_UPLOAD() {
        return getPropertyUTF("DIR_CLOUD_LIVE_VIDEO_UPLOAD");
    }

    public String getDIR_CLOUD_LIVE_IMAGE_UPLOAD() {
        return getPropertyUTF("DIR_CLOUD_LIVE_IMAGE_UPLOAD");
    }

    public String getREDIS_SERVER_IP() {
        return getPropertyUTF("REDIS_SERVER_IP");
    }

    public String getREDIS_SERVER_PORT() {
        return getPropertyUTF("REDIS_SERVER_PORT");
    }

    public String getREDIS_LOGIN_USERNAME() {
        return getPropertyUTF("REDIS_LOGIN_USERNAME");
    }

    public String getREDIS_LOGIN_PASSWORD() {
        return getPropertyUTF("REDIS_LOGIN_PASSWORD");
    }

    public String getREDIS_PTT_TTL() {
        return getPropertyUTF("REDIS_PTT_TTL");
    }
    public Integer getREDIS_DATABASE() {
        return Integer.parseInt(getPropertyUTF("REDIS_DATABASE"));
    }

    public String getMEDIA_SERVER_IP(){
        return getPropertyUTF("MEDIA_SERVER_IP");
    }

    public String getDIR_HUMAN_FACE_UPLOAD() {
        return getPropertyUTF("DIR_HUMAN_FACE_UPLOAD");
    }
    public String getDIR_DEVICE_FILE_UPLOAD(){
        return getPropertyUTF("DIR_DEVICE_FILE_UPLOAD");
    }
    public String HUMAN_FACE_APPID(){
        return getPropertyUTF("HUMAN_FACE_APPID");
    }
    public String HUMAN_FACE_SDKKEY(){
        return getPropertyUTF("HUMAN_FACE_SDKKEY");
    }
    public String HUMAN_FACE_ACTIVE_CODE(){
        return getPropertyUTF("HUMAN_FACE_ACTIVE_CODE");
    }
    public String HUMAN_FACE_LIB_PATH(){
        return getPropertyUTF("HUMAN_FACE_LIB_PATH");
    }

}
